unit Chromium4D.Win;

interface

{$I ..\..\Chromium4D.inc}

uses
  System.SysUtils, System.TypInfo, ceflib, cefvcl, System.Classes, Vcl.Controls,
  Chromium4D, Chromium4D.Classes, Chromium4D.Core;

type
  /// <summary>
  /// Win Chromium Container
  /// </summary>
  TSyChromiumWinContainer = class(TSyChromiumBrowser)
  private
    FParent: TWinControl;
    FWebBrowser: TChromium;
    procedure InitWebContainer;
  protected
    procedure SetURL(const URL: string); override;
    procedure SetDebugger(const Value: Boolean); override;
  protected
    {$REGION ' implementation for ISyChromiumBrowser '}
    /// <summary>
    /// Create Chromium Browser Instance and Init
    /// </summary>
    procedure InitBrowser(aParent: TWinControl; Url: string); override;

    function GetBrowser: TObject;
    {$ENDREGION}

    {$REGION ' Chromium Events CallBack '}
    procedure DoChromiumProcessMessageReceived(Sender: TObject; const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage; out Result: Boolean);

    procedure DoChromiumAddressChange(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const url: ustring);
    procedure DoChromiumAfterCreated(Sender: TObject; const browser: ICefBrowser);
    procedure DoChromiumBeforeBrowse(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; isRedirect: Boolean; out Result: Boolean);
    procedure DoChromiumBeforeClose(Sender: TObject; const browser: ICefBrowser);
    procedure DoChromiumClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);

    procedure DoChromiumGetResourceHandler(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; out Result: ICefResourceHandler);

    procedure DoChromiumBeforeContextMenu(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel);
    procedure DoChromiumBeforeDownload(Sender: TObject; const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const suggestedName: ustring; const callback: ICefBeforeDownloadCallback);
    procedure DoChromiumBeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      const targetUrl, targetFrameName: ustring; {$IFDEF WebKit_2454_UP} targetDisposition: TCefWindowOpenDisposition;
      userGesture: Boolean; {$ENDIF} var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
      var client: ICefClient; var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; out Result: Boolean);
    procedure DoChromiumBeforeResourceLoad(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest;
      {$IFDEF WebKit_2454_UP} const callback: ICefRequestCallback; out Result: TCefReturnValue {$ELSE} out Result: Boolean {$ENDIF} );
    procedure DoChromiumBeforeUnloadDialog(Sender: TObject; const browser: ICefBrowser; const messageText: ustring; isReload: Boolean; const callback: ICefJsDialogCallback; out Result: Boolean);
    procedure DoChromiumCancelGeolocationPermission(Sender: TObject; const browser: ICefBrowser; requestId: Integer);
    {$IFDEF WebKit_2454_UP}
    procedure DoChromiumCertificateError(Sender: TObject; const browser: ICefBrowser; certError: Integer; const requestUrl: ustring;
      const sslInfo: ICefSslInfo; const callback: ICefRequestCallback; out Result: Boolean);
    {$ENDIF}

    procedure DoChromiumConsoleMessage(Sender: TObject; const browser: ICefBrowser; const message, source: ustring; line: Integer; out Result: Boolean);
    procedure DoChromiumContextMenuCommand(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; commandId: Integer; eventFlags: TCefEventFlags; out Result: Boolean);
    procedure DoChromiumContextMenuDismissed(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame);
    procedure DoChromiumDialogClosed(Sender: TObject; const browser: ICefBrowser);
    procedure DoChromiumDownloadUpdated(Sender: TObject; const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const callback: ICefDownloadItemCallback);
    procedure DoChromiumDragEnter(Sender: TObject; const browser: ICefBrowser; const dragData: ICefDragData; mask: TCefDragOperations; out Result: Boolean);
    {$IFDEF WebKit_2454_UP}
    procedure DoChromiumDraggableRegionsChanged(Sender: TObject; const browser: ICefBrowser; regionsCount: NativeUInt; regions: PCefDraggableRegionArray);
    {$ENDIF}
    procedure DoChromiumFavIconUrlChange(Sender: TObject; const browser: ICefBrowser; const iconUrls: TStrings);

    procedure DoChromiumFileDialog(Sender: TObject; const browser: ICefBrowser; mode: TCefFileDialogMode;
      const title,  {$IFDEF WebKit_2454_UP} defaultFilePath: ustring; acceptFilters: TStrings; selectedAcceptFilter: Integer; {$ELSE}
        defaultFileName: ustring;  acceptTypes: TStrings; {$ENDIF}
      const callback: ICefFileDialogCallback; out Result: Boolean);
    procedure DoChromiumFindResult(Sender: TObject; const browser: ICefBrowser; identifier, count: Integer; const selectionRect: PCefRect; activeMatchOrdinal: Integer; finalUpdate: Boolean);
    procedure DoChromiumFullScreenModeChange(Sender: TObject; const browser: ICefBrowser; fullscreen: Boolean);
    procedure DoChromiumGetAuthCredentials(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring; const callback: ICefAuthCallback; out Result: Boolean);
    procedure DoChromiumGotFocus(Sender: TObject; const browser: ICefBrowser);
    procedure DoChromiumJsdialog(Sender: TObject; const browser: ICefBrowser; const originUrl, acceptLang: ustring; dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring; callback: ICefJsDialogCallback; out suppressMessage, Result: Boolean);
    procedure DoChromiumKeyEvent(Sender: TObject; const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: TCefEventHandle; out Result: Boolean);
    procedure DoChromiumLoadEnd(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer);
    procedure DoChromiumLoadError(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; errorCode: Integer; const errorText, failedUrl: ustring);

    procedure DoChromiumLoadingStateChange(Sender: TObject; const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean);
    procedure DoChromiumLoadStart(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame);
    {$IFDEF WebKit_2454_UP}
    procedure DoChromiumOpenUrlFromTab(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; out Result: Boolean);
    {$ENDIF}
    procedure DoChromiumPluginCrashed(Sender: TObject; const browser: ICefBrowser; const pluginPath: ustring);

    procedure DoChromiumPreKeyEvent(Sender: TObject; const browser: ICefBrowser; const event: PCefKeyEvent; osEvent: TCefEventHandle; out isKeyboardShortcut, Result: Boolean);
    procedure DoChromiumProtocolExecution(Sender: TObject; const browser: ICefBrowser; const url: ustring; out allowOsExecution: Boolean);
    procedure DoChromiumQuotaRequest(Sender: TObject; const browser: ICefBrowser; const originUrl: ustring; newSize: Int64;
      const callback: {$IFDEF WebKit_2454_UP} ICefRequestCallback {$ELSE} ICefQuotaCallback {$ENDIF}; out Result: Boolean);

    procedure DoChromiumRenderProcessTerminated(Sender: TObject; const browser: ICefBrowser; status: TCefTerminationStatus);

    procedure DoChromiumRenderViewReady(Sender: TObject; const browser: ICefBrowser);

    procedure DoChromiumRequestGeolocationPermission(Sender: TObject; const browser: ICefBrowser; const requestingUrl: ustring;
      requestId: Integer; const callback: ICefGeolocationCallback{$IFDEF WebKit_2454_UP}; out Result: Boolean {$ENDIF});
    procedure DoChromiumResetDialogState(Sender: TObject; const browser: ICefBrowser);
    procedure DoChromiumResourceRedirect(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame;
      {$IFDEF WebKit_2454_UP} const request: ICefRequest; {$ELSE} const oldUrl: ustring; {$ENDIF} var newUrl: ustring);
    procedure DoChromiumResourceResponse(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; out Result: Boolean);
    procedure DoChromiumRunModal(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
    procedure DoChromiumSetFocus(Sender: TObject; const browser: ICefBrowser; source: TCefFocusSource; out Result: Boolean);
    procedure DoChromiumStatusMessage(Sender: TObject; const browser: ICefBrowser; const value: ustring);
    procedure DoChromiumTakeFocus(Sender: TObject; const browser: ICefBrowser; next: Boolean);
    procedure DoChromiumTitleChange(Sender: TObject; const browser: ICefBrowser; const title: ustring);
    procedure DoChromiumTooltip(Sender: TObject; const browser: ICefBrowser; var text: ustring; out Result: Boolean);
    {$ENDREGION}
  public
    constructor Create(AChromium: TSyChromium); override;
    destructor Destroy; override;
  end;

implementation

  uses System.Win.Registry, Winapi.Windows, Winapi.ShellAPI, Chromium4D.Browser.Process, Chromium4D.Utils, Utils;

{ TSyChromiumWinContainer }

constructor TSyChromiumWinContainer.Create(AChromium: TSyChromium);
begin
  inherited;
  FParent := nil;
  FWebBrowser := nil;
end;

procedure TSyChromiumWinContainer.InitWebContainer;
begin
  {$REGION 'Chromium Event CallBack Binding'}
  //4
  FWebBrowser.OnProcessMessageReceived := DoChromiumProcessMessageReceived;
  FWebBrowser.OnLoadStart              := DoChromiumLoadStart;
  FWebBrowser.OnLoadEnd                := DoChromiumLoadEnd;
  FWebBrowser.OnLoadError              := DoChromiumLoadError;
  //9
  FWebBrowser.OnTakeFocus              := DoChromiumTakeFocus;
  FWebBrowser.OnSetFocus               := DoChromiumSetFocus;
  FWebBrowser.OnGotFocus               := DoChromiumGotFocus;
  FWebBrowser.OnBeforeContextMenu      := DoChromiumBeforeContextMenu;
  FWebBrowser.OnContextMenuCommand     := DoChromiumContextMenuCommand;
  FWebBrowser.OnContextMenuDismissed   := DoChromiumContextMenuDismissed;
  FWebBrowser.OnPreKeyEvent            := DoChromiumPreKeyEvent;
  FWebBrowser.OnKeyEvent               := DoChromiumKeyEvent;
  FWebBrowser.OnLoadingStateChange     := DoChromiumLoadingStateChange;
  //12
  FWebBrowser.OnAddressChange          := DoChromiumAddressChange;
  FWebBrowser.OnTitleChange            := DoChromiumTitleChange;
  {$IFDEF WebKit_2623}
  FWebBrowser.OnFavIconUrlChange       := DoChromiumFavIconUrlChange;
  FWebBrowser.OnFullScreenModeChange   := DoChromiumFullScreenModeChange;
  {$ENDIF}
  FWebBrowser.OnTooltip                := DoChromiumTooltip;
  FWebBrowser.OnStatusMessage          := DoChromiumStatusMessage;
  FWebBrowser.OnConsoleMessage         := DoChromiumConsoleMessage;
  FWebBrowser.OnBeforeDownload         := DoChromiumBeforeDownload;
  FWebBrowser.OnDownloadUpdated        := DoChromiumDownloadUpdated;
  FWebBrowser.OnRequestGeolocationPermission := DoChromiumRequestGeolocationPermission;
  {$IFDEF WebKit_2623}
  FWebBrowser.OnCancelGeolocationPermission  := DoChromiumCancelGeolocationPermission;
  {$ENDIF}
  FWebBrowser.OnJsdialog                     := DoChromiumJsdialog;
  //8
  FWebBrowser.OnBeforeUnloadDialog           := DoChromiumBeforeUnloadDialog;
  FWebBrowser.OnResetDialogState             := DoChromiumResetDialogState;
  FWebBrowser.OnDialogClosed                 := DoChromiumDialogClosed;
  FWebBrowser.OnBeforePopup                  := DoChromiumBeforePopup;
  FWebBrowser.OnAfterCreated                 := DoChromiumAfterCreated;
  FWebBrowser.OnBeforeClose                  := DoChromiumBeforeClose;
  FWebBrowser.OnRunModal                     := DoChromiumRunModal;
  FWebBrowser.OnClose                        := DoChromiumClose;
  //13
  FWebBrowser.OnBeforeBrowse                 := DoChromiumBeforeBrowse;
  {$IFDEF WebKit_2623}
  FWebBrowser.OnOpenUrlFromTab               := DoChromiumOpenUrlFromTab;
  {$ENDIF}
  FWebBrowser.OnBeforeResourceLoad           := DoChromiumBeforeResourceLoad;
  FWebBrowser.OnGetResourceHandler           := DoChromiumGetResourceHandler;
  FWebBrowser.OnResourceRedirect             := DoChromiumResourceRedirect;
  {$IFDEF WebKit_2623}
  FWebBrowser.OnResourceResponse             := DoChromiumResourceResponse;
  {$ENDIF}
  FWebBrowser.OnGetAuthCredentials           := DoChromiumGetAuthCredentials;
  {$IFDEF WebKit_2623}
  FWebBrowser.OnQuotaRequest                 := DoChromiumQuotaRequest;
  {$ENDIF}
  FWebBrowser.OnProtocolExecution            := DoChromiumProtocolExecution;
  {$IFDEF WebKit_2623}
  FWebBrowser.OnCertificateError             := DoChromiumCertificateError;
  {$ENDIF}
  FWebBrowser.OnPluginCrashed                := DoChromiumPluginCrashed;
  {$IFDEF WebKit_2623}
  FWebBrowser.OnRenderViewReady              := DoChromiumRenderViewReady;
  {$ENDIF}
  FWebBrowser.OnRenderProcessTerminated      := DoChromiumRenderProcessTerminated;
  //4
  FWebBrowser.OnFileDialog                   := DoChromiumFileDialog;
  FWebBrowser.OnDragEnter                    := DoChromiumDragEnter;
  {$IFDEF WebKit_2623}
  FWebBrowser.OnDraggableRegionsChanged      := DoChromiumDraggableRegionsChanged;
  FWebBrowser.OnFindResult                   := DoChromiumFindResult;
  {$ENDIF}

  {$ENDREGION}
end;

procedure TSyChromiumWinContainer.InitBrowser(aParent: TWinControl; Url: string);
begin
  if FWebBrowser <> nil then
    Exit;
  FParent := aParent;

  FWebBrowser := TChromium.Create(FParent);
  FWebBrowser.DefaultUrl := Url;
  InitWebContainer;
  FWebBrowser.Parent     := FParent;
  FWebBrowser.Align      := alClient;
  FWebBrowser.HandleNeeded;
  FWebBrowser.Show;
  FWebBrowser.Repaint;
  {$IFNDEF CEF_MULTI_THREADED_MESSAGE_LOOP}
  FWebBrowser.Load(FWebBrowser.DefaultUrl);
  {$ENDIF}
  inherited;
end;

destructor TSyChromiumWinContainer.Destroy;
begin
  FParent := nil;
  FWebBrowser := nil;
  inherited;
end;

procedure TSyChromiumWinContainer.DoChromiumAddressChange(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const url: ustring);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumAddressChange url: %s', [url]);
end;

procedure TSyChromiumWinContainer.DoChromiumAfterCreated(Sender: TObject; const browser: ICefBrowser);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumAfterCreated');
  TSyBrowserProcess(FChromium.Process).AfterBrowserCreated(browser);
end;

procedure TSyChromiumWinContainer.DoChromiumBeforeBrowse(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const request: ICefRequest; isRedirect: Boolean; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumBeforeBrowse: ' + request.Url);
end;

procedure TSyChromiumWinContainer.DoChromiumBeforeClose(Sender: TObject; const browser: ICefBrowser);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumBeforeClose');
  TSyBrowserProcess(FChromium.Process).BeforeBrowserClosed(browser);
  Self.Free;
end;

procedure TSyChromiumWinContainer.DoChromiumBeforeContextMenu(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumBeforeContextMenu');
end;

procedure TSyChromiumWinContainer.DoChromiumBeforeDownload(Sender: TObject; const browser: ICefBrowser;
  const downloadItem: ICefDownloadItem; const suggestedName: ustring; const callback: ICefBeforeDownloadCallback);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumBeforeDownload');
end;

procedure TSyChromiumWinContainer.DoChromiumBeforePopup(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const targetUrl, targetFrameName: ustring; {$IFDEF WebKit_2454_UP} targetDisposition: TCefWindowOpenDisposition;
      userGesture: Boolean; {$ENDIF} var popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient;
    var settings: TCefBrowserSettings; var noJavascriptAccess: Boolean; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumBeforePopup');
end;

procedure TSyChromiumWinContainer.DoChromiumBeforeResourceLoad(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const request: ICefRequest;
  {$IFDEF WebKit_2454_UP} const callback: ICefRequestCallback; out Result: TCefReturnValue {$ELSE} out Result: Boolean {$ENDIF});
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumBeforeResourceLoad: ' + request.Url);
end;

procedure TSyChromiumWinContainer.DoChromiumBeforeUnloadDialog(Sender: TObject; const browser: ICefBrowser;
  const messageText: ustring; isReload: Boolean; const callback: ICefJsDialogCallback; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumBeforeUnloadDialog');
end;

procedure TSyChromiumWinContainer.DoChromiumCancelGeolocationPermission(Sender: TObject; const browser: ICefBrowser;
  requestId: Integer);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumCancelGeolocationPermission');
end;

{$IFDEF WebKit_2454_UP}
procedure TSyChromiumWinContainer.DoChromiumCertificateError(Sender: TObject; const browser: ICefBrowser;
  certError: Integer; const requestUrl: ustring; const sslInfo: ICefSslInfo; const callback: ICefRequestCallback; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumCertificateError');
end;
{$ENDIF}

procedure TSyChromiumWinContainer.DoChromiumClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumClose');
end;

procedure TSyChromiumWinContainer.DoChromiumConsoleMessage(Sender: TObject; const browser: ICefBrowser;
  const message, source: ustring; line: Integer; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumConsoleMessage: [line: %d]  %s', [line, source]);
end;

procedure TSyChromiumWinContainer.DoChromiumContextMenuCommand(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const params: ICefContextMenuParams; commandId: Integer; eventFlags: TCefEventFlags; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumContextMenuCommand');
end;

procedure TSyChromiumWinContainer.DoChromiumContextMenuDismissed(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumContextMenuDismissed');
end;

procedure TSyChromiumWinContainer.DoChromiumDialogClosed(Sender: TObject; const browser: ICefBrowser);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumDialogClosed');
end;

procedure TSyChromiumWinContainer.DoChromiumDownloadUpdated(Sender: TObject; const browser: ICefBrowser;
  const downloadItem: ICefDownloadItem; const callback: ICefDownloadItemCallback);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumDownloadUpdated');
end;

procedure TSyChromiumWinContainer.DoChromiumDragEnter(Sender: TObject; const browser: ICefBrowser;
  const dragData: ICefDragData; mask: TCefDragOperations; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumDragEnter');
end;

{$IFDEF WebKit_2454_UP}
procedure TSyChromiumWinContainer.DoChromiumDraggableRegionsChanged(Sender: TObject; const browser: ICefBrowser;
  regionsCount: NativeUInt; regions: PCefDraggableRegionArray);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumDraggableRegionsChanged');
end;
{$ENDIF}

procedure TSyChromiumWinContainer.DoChromiumFavIconUrlChange(Sender: TObject; const browser: ICefBrowser;
  const iconUrls: TStrings);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumFavIconUrlChange: ' + iconUrls.Text);
end;

procedure TSyChromiumWinContainer.DoChromiumFileDialog(Sender: TObject; const browser: ICefBrowser;
   mode: TCefFileDialogMode; const title, {$IFDEF WebKit_2454_UP} defaultFilePath: ustring; acceptFilters: TStrings; selectedAcceptFilter: Integer; {$ELSE}
        defaultFileName: ustring;  acceptTypes: TStrings; {$ENDIF} const callback: ICefFileDialogCallback; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumFileDialog');
end;

procedure TSyChromiumWinContainer.DoChromiumFindResult(Sender: TObject; const browser: ICefBrowser;
  identifier, count: Integer; const selectionRect: PCefRect; activeMatchOrdinal: Integer; finalUpdate: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumFindResult');
end;

procedure TSyChromiumWinContainer.DoChromiumFullScreenModeChange(Sender: TObject; const browser: ICefBrowser; fullscreen: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumFullScreenModeChange');
end;

procedure TSyChromiumWinContainer.DoChromiumGetAuthCredentials(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring;
  const callback: ICefAuthCallback; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumGetAuthCredentials');
end;

procedure TSyChromiumWinContainer.DoChromiumGetResourceHandler(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const request: ICefRequest; out Result: ICefResourceHandler);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumGetResourceHandler: ' + request.Url);

//  Result := TMyCefResourceHandle.Create(browser, frame, '', request);
end;

procedure TSyChromiumWinContainer.DoChromiumGotFocus(Sender: TObject; const browser: ICefBrowser);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumGotFocus');
end;

procedure TSyChromiumWinContainer.DoChromiumJsdialog(Sender: TObject; const browser: ICefBrowser;
  const originUrl, acceptLang: ustring; dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring;
  callback: ICefJsDialogCallback; out suppressMessage, Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumJsdialog');
end;

procedure TSyChromiumWinContainer.DoChromiumKeyEvent(Sender: TObject; const browser: ICefBrowser;
  const event: PCefKeyEvent; osEvent: TCefEventHandle; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumKeyEvent');
end;

procedure TSyChromiumWinContainer.DoChromiumLoadEnd(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; httpStatusCode: Integer);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumLoadEnd');
end;

procedure TSyChromiumWinContainer.DoChromiumLoadError(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; errorCode: Integer; const errorText, failedUrl: ustring);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumLoadError');
end;

procedure TSyChromiumWinContainer.DoChromiumLoadingStateChange(Sender: TObject; const browser: ICefBrowser;
  isLoading, canGoBack, canGoForward: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumLoadingStateChange');
end;

procedure TSyChromiumWinContainer.DoChromiumLoadStart(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumLoadStart');
end;

{$IFDEF WebKit_2454_UP}
procedure TSyChromiumWinContainer.DoChromiumOpenUrlFromTab(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const targetUrl: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
  out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumOpenUrlFromTab');
end;
{$ENDIF}

procedure TSyChromiumWinContainer.DoChromiumPluginCrashed(Sender: TObject; const browser: ICefBrowser;
  const pluginPath: ustring);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumPluginCrashed');
end;

procedure TSyChromiumWinContainer.DoChromiumPreKeyEvent(Sender: TObject; const browser: ICefBrowser;
  const event: PCefKeyEvent; osEvent: TCefEventHandle; out isKeyboardShortcut, Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumPreKeyEvent');
end;

procedure TSyChromiumWinContainer.DoChromiumProcessMessageReceived(Sender: TObject; const browser: ICefBrowser;
  sourceProcess: TCefProcessId; const message: ICefProcessMessage; out Result: Boolean);
begin
  Logger.Debug('=====TSyChromiumWinContainer.DoProcessMessageReceived: SourceProcessId: %s; Message: %s', [GetEnumName(TypeInfo(TCefProcessId), Ord(sourceProcess)), message.Name]);
  Result := FChromium.Process.MessageReceived(browser, sourceProcess, message);
end;

procedure TSyChromiumWinContainer.DoChromiumProtocolExecution(Sender: TObject; const browser: ICefBrowser;
  const url: ustring; out allowOsExecution: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumProtocolExecution');
end;

procedure TSyChromiumWinContainer.DoChromiumQuotaRequest(Sender: TObject; const browser: ICefBrowser;
  const originUrl: ustring; newSize: Int64; const callback: {$IFDEF WebKit_2454_UP} ICefRequestCallback {$ELSE} ICefQuotaCallback {$ENDIF};
  out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumQuotaRequest');
end;

procedure TSyChromiumWinContainer.DoChromiumRenderProcessTerminated(Sender: TObject; const browser: ICefBrowser;
  status: TCefTerminationStatus);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumRenderProcessTerminated');
end;

procedure TSyChromiumWinContainer.DoChromiumRenderViewReady(Sender: TObject; const browser: ICefBrowser);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumRenderViewReady');
end;

procedure TSyChromiumWinContainer.DoChromiumRequestGeolocationPermission(Sender: TObject; const browser: ICefBrowser;
  const requestingUrl: ustring; requestId: Integer; const callback: ICefGeolocationCallback{$IFDEF WebKit_2454_UP}; out Result: Boolean {$ENDIF});
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumRequestGeolocationPermission');
end;

procedure TSyChromiumWinContainer.DoChromiumResetDialogState(Sender: TObject; const browser: ICefBrowser);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumResetDialogState');
end;

procedure TSyChromiumWinContainer.DoChromiumResourceRedirect(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame;  {$IFDEF WebKit_2454_UP} const request: ICefRequest; {$ELSE} const oldUrl: ustring; {$ENDIF}  var newUrl: ustring);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumResourceRedirect: ' +
    {$IFDEF WebKit_2454_UP} request.Url {$ELSE} oldUrl {$ENDIF} );
end;

procedure TSyChromiumWinContainer.DoChromiumResourceResponse(Sender: TObject; const browser: ICefBrowser;
  const frame: ICefFrame; const request: ICefRequest; const response: ICefResponse; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumResourceResponse: ' + request.Url);
end;

procedure TSyChromiumWinContainer.DoChromiumRunModal(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumRunModal');
end;

procedure TSyChromiumWinContainer.DoChromiumSetFocus(Sender: TObject; const browser: ICefBrowser; source: TCefFocusSource;
  out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumSetFocus');
end;

procedure TSyChromiumWinContainer.DoChromiumStatusMessage(Sender: TObject; const browser: ICefBrowser;
  const value: ustring);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumStatusMessage: ' + value);
end;

procedure TSyChromiumWinContainer.DoChromiumTakeFocus(Sender: TObject; const browser: ICefBrowser; next: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumTakeFocus');
end;

procedure TSyChromiumWinContainer.DoChromiumTitleChange(Sender: TObject; const browser: ICefBrowser;
  const title: ustring);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumTitleChange: ' + title);
end;

procedure TSyChromiumWinContainer.DoChromiumTooltip(Sender: TObject; const browser: ICefBrowser;
  var text: ustring; out Result: Boolean);
begin
  Logger.Debug(TCefThreadHelper.CheckCurrentThread + ' | ' +'=====TSyChromiumWinContainer.DoChromiumTooltip');
end;

function TSyChromiumWinContainer.GetBrowser: TObject;
begin
  Result := FChromium;
end;

procedure TSyChromiumWinContainer.SetDebugger(const Value: Boolean);
var
  reg: TRegistry;
  path, url: string;
begin
//  reg := TRegistry.Create;
//  try
//    reg.RootKey := HKEY_LOCAL_MACHINE;
//    if reg.OpenKeyReadOnly('\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe') then
//      path := ExtractFilePath(reg.ReadString('')) else
//      Exit;
//  finally
//    reg.Free;
//  end;

//  if DirectoryExists(path) then
//  begin
//    FWebBrowser.ShowDevTools;
//  end;
//
  if Value then
    FWebBrowser.ShowDevTools(nil)
  else
    FWebBrowser.CloseDevTools;

  FDebugger := Value;
end;

procedure TSyChromiumWinContainer.SetURL(const URL: string);
begin
  FWebBrowser.Load(URL);
end;

initialization
  ContainerClass := TSyChromiumWinContainer;

finalization

end.

